/**
 * 
 */
package com.erdos.upc.dao.ibatis;

import java.util.HashMap;
import java.util.Map;

import com.erdos.common.dao.IBatisGenericDaoImpl;
import com.erdos.upc.dao.GroupDao;
import com.erdos.upc.entity.Group;



public class GroupDaoImpl extends IBatisGenericDaoImpl<Group> implements
		GroupDao {
	/**
	 * 根据group名字查询
	 * @param name
	 * @return
	 */
	public Group findByName(String name) {

		return (Group) this.getSqlMapClientTemplate().queryForObject(
				"Group.findByName", name);
	}

	/**
	 * 删除用户组所有角色关联记录
	 * @param groupSid
	 */
	public void deleteGroupAllRoles(Long groupSid) {
		this.getSqlMapClientTemplate().delete("Group.deleteGroupAllRoles",
				groupSid);

	}

	/**
	 * 删除用户组所有用户关联记录
	 * @param groupSid
	 */
	public void deleteGroupAllUsers(Long groupSid) {
		this.getSqlMapClientTemplate().delete("Group.deleteGroupAllUsers",
				groupSid);

	}

	/**
	 * 删除角色关联记录
	 * @param groupSid
	 * @param roleSid
	 */
	public void deleteGroupRole(Long groupSid, Long roleSid) {
		Map<String, Long> conditions = new HashMap<String, Long>();
		conditions.put("roleSid", roleSid);
		conditions.put("groupSid", groupSid);
		this.getSqlMapClientTemplate().delete("Group.deleteGroupRole",
				conditions);

	}

	/**
	 * 删除用户关联记录
	 * @param groupSid
	 * @param userSid
	 */
	public void deleteGroupUser(Long groupSid, Long userSid) {
		Map<String, Long> conditions = new HashMap<String, Long>();
		conditions.put("userSid", userSid);
		conditions.put("groupSid", groupSid);
		this.getSqlMapClientTemplate().delete("Group.deleteGroupUser",
				conditions);
	}

	/**
	 * 插入角色关联记录
	 * @param groupSid
	 * @param roleSid
	 */
	public void insertGroupRole(Map<String, Object> params) {
//		Map<String, Long> conditions = new HashMap<String, Long>();
//		conditions.put("roleSid", roleSid);
//		conditions.put("groupSid", groupSid);
		this.getSqlMapClientTemplate().insert("Group.insertGroupRole",
				params);

	}

	/**
	 * 插入用户关联记录
	 * @param groupSid
	 * @param userSid
	 */
	public void insertGroupUser(Map<String, Object> params) {
//	  	Map<String, Long> conditions = new HashMap<String, Long>();
//		conditions.put("userSid", userSid);
//		conditions.put("groupSid", groupSid);
		this.getSqlMapClientTemplate().insert("Group.insertGroupUser",
				params);
	}

}
